package com.liu.user.controller;

import com.liu.user.service.UserService;
import com.liu.user.service.impl.UserServiceImpl;
import com.liu.user.entity.User;
import entity.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import status.CodeEnum;

@RestController
@Slf4j
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping
    public Result addUser(@RequestBody User user){
        userService.addUser(user);
     return  new Result(true, CodeEnum.OK.getCode(),"用户保存成功");
    }

    @PostMapping("/login")
    public Result login(@RequestBody User user){
          user=   userService.login(user.getName(),user.getPassword());

        return  new Result(true, CodeEnum.OK.getCode(),"用户登录成功",user);
    }

}
